﻿<!--#include file="../lib/base.asp"-->
<!--#include file="../theme.asp"-->
<%
sdcms.checkuserlogin
dim act:act=lcase(sdcms.fget("act",0))
select case act
	case "checkdb":checkdb()
	case else
		sdcms.show theme_userbase,""
end select

sub checkdb()
	dim t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,data
	t0=sdcms.enhtml(sdcms.fpost("truename",0))
	t1=sdcms.enhtml(sdcms.fpost("sex",0))
	t2=sdcms.enhtml(sdcms.fpost("birthday",0))
	t3=sdcms.enhtml(sdcms.fpost("qq",0))
	t4=sdcms.enhtml(sdcms.fpost("msn",0))
	t5=sdcms.enhtml(sdcms.fpost("mobile",0))
	t6=sdcms.enhtml(sdcms.fpost("tel",0))
	t7=sdcms.enhtml(sdcms.fpost("job",0))
	t8=sdcms.enhtml(sdcms.fpost("zipcode",0))
	t9=sdcms.enhtml(sdcms.fpost("address",0))
	dim percent:percent=3

	data="array("

	if sdcms.strlen(t0)>0 then
		if not(sdcms.checkstr(t0,"cn")) then
			sdcms.ajaxjson "姓名必须为中文",0
			exit sub
		end if
		percent=percent+1
		data=data&"array(""truename"",t0,6,1),"
	else
		data=data&"array(""truename"","""",0,1),"
	end if
	select case t1
		case "1","2"
			percent=percent+1
			data=data&"array(""sex"",t1,1,1),"
		case else
		'data=data&"array(""sex"",0,0),"
	end select
	if sdcms.strlen(t2)>0 then
		if t2<>"0-0-0" then
			if not isdate(t2) then
				sdcms.ajaxjson "0&#29983;&#26085;&#26684;&#24335;&#38169;&#35823;",0
				exit sub
			end if
			t2=sdcms.getdate(t2,"-",1)
			percent=percent+1
			data=data&"array(""birthday"",t2,12,1),"
		else
			t2="1753-01-01"
			data=data&"array(""birthday"",t2,12,1),"
		end if
	end if
	if sdcms.strlen(t3)>0 then
		if not(sdcms.checkstr(t3,"qq")) then
			sdcms.ajaxjson "QQ号码不正确",0
			exit sub
		end if
		percent=percent+1
		data=data&"array(""qq"",t3,17,1),"
	else
		data=data&"array(""qq"","""",0,1),"
	end if
	if sdcms.strlen(t4)>0 then
		if not(sdcms.checkstr(t4,"email")) then
			sdcms.ajaxjson "MSN格式不正确",0
			exit sub
		end if
		percent=percent+1
		data=data&"array(""msn"",t4,50,1),"
	else
		data=data&"array(""msn"","""",0,1),"
	end if
	if sdcms.strlen(t5)>0 then
		if not(sdcms.checkstr(t5,"mobile")) then
			sdcms.ajaxjson "手机号码格式不正确",0
			exit sub
		end if
		percent=percent+1
		data=data&"array(""mobile"",t5,11,1),"
	else
		data=data&"array(""mobile"","""",0,1),"
	end if
	if sdcms.strlen(t6)>0 then
		if not(sdcms.checkstr(t6,"tel")) then
			sdcms.ajaxjson "电话号码格式不正确",0
			exit sub
		end if
		percent=percent+1
		data=data&"array(""tel"",t6,13,1),"
	else
		data=data&"array(""tel"","""",0,1),"
	end if
	if sdcms.strlen(t7)>0 then
		percent=percent+1
		data=data&"array(""job"",t7,12,1),"
	else
		data=data&"array(""job"","""",0,1),"
	end if
	if sdcms.strlen(t8)>0 then
		if not(sdcms.checkstr(t8,"zipcode")) then
			sdcms.ajaxjson "邮编格式不正确",0
			exit sub
		end if
		percent=percent+1
		data=data&"array(""zipcode"",t8,8,1),"
	else
		data=data&"array(""zipcode"","""",0,1),"
	end if
	if sdcms.strlen(t9)>0 then
		percent=percent+1
		data=data&"array(""address"",t9,255,1),"
	else
		data=data&"array(""address"","""",0,1),"
	end if
	percent=clng((percent/13)*100)

	dim userdata:userdata=sdcms.userinfo
	dim useridnum:useridnum=sdcms.db.dbcount("sd_user_data","userid="&userdata(0)&"")
	if useridnum=0 then
		data=data&"array(""userid"",userdata(0),0,0),"
	end if
	if right(data,1)="," then
		data=left(data,len(data)-1)
	end if
	data=data&")"
	
	if percent>23 then 
		'检查是否已经存在，存在就更新，不存在就创建
		if useridnum=0 then
			sdcms.db.insert "sd_user_data",eval(data)
		else
			sdcms.db.dbupdate "sd_user_data","userid="&userdata(0)&"",eval(data)
		end if
	end if
	'更新资料完整率
	sdcms.db.dbupdate "sd_user","id="&userdata(0)&"",array(array("percent",percent,3,0))
	sdcms.resetuserinfo "u.id="&userdata(0)&""
	sdcms.ajaxjson "&#20445;&#23384;&#25104;&#21151;",1
end sub
sdcms.db.dbclose
%>